package cl.kaisanetwork.kaisaportal.page.accounts;

import java.util.Date;

import org.springframework.stereotype.Component;

import cl.kaisanetwork.kaisaportal.page.BorderPage;
import cl.kaisanetwork.kaisaportal.page.home.Home;

@Component
public class Login extends BorderPage {

	private static final long serialVersionUID = 1L;

	@Override
	public void onInit() {
		super.onInit();
		if(googleUser != null) {
			if(currentUser == null)
				setRedirect(SignUp.class);
			else {
				usuarioService.makeLogin(currentUser.getId() ,new Date(), getContext().getRequest().getRemoteAddr());
				setRedirect(Home.class);
			}
		} else {
			setRedirect(Home.class);
		}
	}
	
	@Override
	public boolean onSecurityCheck() {
		if(!super.onSecurityCheck()) {
			setRedirect(SignUp.class);
			return false;
		}
		return true;
	}
}